package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.BrandMapper;
import com.qingcheng.dao.CategoryMapper;
import com.qingcheng.dao.SpecMapper;
import com.qingcheng.pojo.goods.Category;
import com.qingcheng.service.goods.AutoAddDataToRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;
import java.util.Map;

/**
 * Welcome to the most Amazing IntelliJ IIIDEA.
 * Creat0r: ^_^ fffantianxing ^_^
 * Date: 2019-07-10
 * Time: 21:42
 */
@Service
public class AutoAddDataToRedisServiceImpl implements AutoAddDataToRedisService {

    @Autowired
    private BrandMapper brandMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private SpecMapper specMapper;

    @Override
    public void addAllBrandsToRedis() {
        List<Category> categoryList = categoryMapper.selectAll();
        for (Category category : categoryList) {
            List<Map> brand = brandMapper.fingBrandByCategoryName(category.getName());
            redisTemplate.boundHashOps("brand").put(category.getName(),brand);
        }
    }

    @Override
    public void addAllSpecToRedis() {
        List<Category> categoryList = categoryMapper.selectAll();
        for (Category category : categoryList) {
            List<Map> specList = specMapper.findSpecByCategoryName(category.getName());
            redisTemplate.boundHashOps("spec").put(category.getName(),specList);
        }

    }
}
